<?php

namespace App\Console\Commands\Tools\Menus;

use App\Kuafu\Category\Model\CategoryModel;
use App\Kuafu\Product\Model\Product;
use App\Kuafu\ProductMenu\Model\ProductMenu;
use App\Kuafu\Shop\Model\Shop;
use Illuminate\Console\Command;

class ExportMenusShopInfoCommand extends Command
{

    protected $signature = 'tools:export-menus-shop-info';


    protected $description = '导出门店菜单';

    public function handle()
    {
        $menuList = ProductMenu::query()->get();

        foreach ($menuList as $menu) {
            $shopList = Shop::query()->where('menuId', $menu->id)->get();

            $rowData = '菜单名称,门店名称,门店编号,省市区';

            foreach ($shopList as $item) {
                $rowData .= vsprintf("\n%s,%s,%s,%s", [
                    $menu['name'],
                    $item['name'],
                    $item['shopCode'],
                    $item['addressPrefix']
                ]);
            }

            $filename = str_replace(['【', '】', '/'], [''], $menu->name);

            file_put_contents('./demo/' . $filename . '.csv', $rowData);
        }

    }
}
